package com.zhao.base;

import com.zhao.model.Ticket;
import com.zhao.util.HttpRequest;

import net.sf.json.JSONObject;

public class TicketBase{
	
	private static String url="https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=jsapi";
	
	public static Ticket getTicket(String accessToken){
		url=url.replace("ACCESS_TOKEN",accessToken);
		JSONObject json=HttpRequest.httpsRequest(url,"GET", null);
		String errmsg=json.getString("errmsg");
		if(errmsg.equals("ok")) {
			Ticket ticket=new Ticket();
			ticket.setTicket(json.getString("ticket"));
			ticket.setExpiresIn(json.getString("expires_in"));
			return ticket;
		}
		return null;
	}
}
